from flask import *
from flask_cors import CORS
import config
from exts import *
from models import *
from bluePrints.home import home
from bluePrints.image import image
from bluePrints.baike import baike
from bluePrints.auth import auth
from bluePrints.teizi import tieziA
from bluePrints.admin import admin
from bluePrints.search import search
from bluePrints.home2 import home2


from extends.websocket import socketio

from flask_migrate import Migrate
from flask_mail import Mail



app = Flask(__name__)
app.config.from_object(config)  # 导入配置文件

host =[
    "http://127.0.0.1:5173",
    "http://127.0.0.1:5174",
    "http://localhost:5173",
    "http://localhost:5174",
]

CORS(app, origins=host,supports_credentials=True) # CORS 域名放行

socketio.init_app(app, cors_allowed_origins=host)  # 初始化socketio

db.init_app(app)  # 初始化数据库
mail.init_app(app)
# cache.init_app(app)  # 初始化缓存


migrate = Migrate(app, db)  # 初始化迁移脚本

app.register_blueprint(home)
app.register_blueprint(home2)
app.register_blueprint(baike)
app.register_blueprint(auth)
app.register_blueprint(tieziA)
app.register_blueprint(image)
app.register_blueprint(admin)
app.register_blueprint(search)



@app.route('/')
def hello():
    return 'Hello World!'


if __name__ == '__main__':
    socketio.run(app, host='0.0.0.0', port=5000, debug=True)